<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
    <link rel="stylesheet" href="css/layer.css" />
	<link rel="icon" href="images/favicon.png">
</head>
<body id="test">
	<div class="login_logo">
		<div class="login_img">
			<img src="images/logo.png">
		</div>
		<p class="login_tit">聚商优品会员登录</p>
	</div>
	<div class="inpt_div">
		<div class="phone_div">
			<span class="phone_icon">
				<img src="images/phone.png"/>
			</span>
			<input type="text" class="phone_inpt" placeholder="请输入账号" id="login_phone"/>
			<span class="span_img" id="login_div">
				<img src="images/x.png" id="x_img"/>
			</span>
		</div>
		<div class="phone_div" style="margin-top:0;">
			<span class="phone_icon">
				<img src="images/pasd.png"/>
			</span>
			<input type="password" class="phone_inpt" placeholder="请输入密码" id="login_pasd"/>
			<span class="span_img" id="pasd_div">
				<img src="images/x.png" id="x_img"/>
			</span>
		</div>
		<button class="btn_login">登录</button>
	</div>
	<!--忘记密码-->
	<div class="forget_pasd">忘记密码？</div>
</body>
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript" src="js/layer.js" ></script>
<script type="text/javascript">
	autodivheight();
	function autodivheight() { //函数：获取尺寸  
		//获取浏览器窗口高度  
		var winHeight = 0;
		if(window.innerHeight) {
			winHeight = window.innerHeight;
		} else if((document.body) && (document.body.clientHeight)) {
			winHeight = document.body.clientHeight;
			//通过深入Document内部对body进行检测，获取浏览器窗口高度  
		}
		if(document.documentElement && document.documentElement.clientHeight) {
			winHeight = document.documentElement.clientHeight;
			//DIV高度为浏览器窗口的高度  
			document.getElementById("test").style.height = winHeight + "px";
		}
	}
	window.onresize = autodivheight; //浏览器窗口发生变化时同时变化DIV高度  
	//忘记密码跳转
	$(".forget_pasd").click(function(){
		window.location.href = "/forgetpasd"
	})
	//账号消除
	$("#login_phone").on({
	    focus:function() {
	      $("#login_div").show();
	    },
	    blur:function() {
	      setTimeout(function(){
	        $("#login_div").hide();
	      },0)
	    }
	})
	$("#login_div").click(function(){ 
		$("#login_phone").val("")
	})
	//密码消除
	$("#login_pasd").on({
		focus:function() {
	      $("#pasd_div").show();
	    },
	    blur:function() {
	      setTimeout(function(){
	        $("#pasd_div").hide();
	      },0)
	    }
	})
	$("#pasd_div").click(function(){ 
		$("#login_pasd").val("")
	})
	//登录按钮
	$(".btn_login").click(function(){
		var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
		if($('#login_phone').val() == ""){
			layer.msg('请输入账号（手机号）', {
			  time:2000
			});
		}else if(!myreg.test($('#login_phone').val())){
			layer.msg('请输入正确的手机号', {
			  time:2000
			});
		}else{
            var mobile_number= $("#login_phone").val();
            var password= $("#login_pasd").val();
            //var str = '{ "mobile_number": "'+mobile_number+'", "password": "'+password+'" }';
            $.ajax({
                type:"POST",
                url:"/users/login",
				contentType: "application/json;charset=UTF-8",
				dataType: "json",
                data:JSON.stringify({"mobile_number": mobile_number, "password": password}),
                success:function (data) {
                    if(data.code=="success"){
                        var storage=window.localStorage;
                        storage.promoCode=data.data.promoCode;
                        storage.token=data.data.token;
                        storage.mobile_number=mobile_number;
                        storage.password=password;
                        window.location.href ="/index";
					}else{
                        layer.msg('账号或密码错误', {
                            time:2000
                        });
					}
                }
            })
		}
	})
	$(function () {
        var storage=window.localStorage;
        if(storage.password!=undefined && storage.mobile_number!=undefined){
            $('#login_phone').val(storage.mobile_number);
            $('#login_pasd').val(storage.password);
		}
    })
</script>
</html>